﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace odinshrine
{
    //Classe qui gere le background, le nombre de points, le temps ecoule...
    class Interface
    {
        bool multi =false;
        public int nbPoints;
        int temps_lvl = 150;
        Texture2D croix, fondVie, croix2;
        public Sprite fond1 = new Sprite();
        public Sprite fond2 = new Sprite();
        private SpriteFont font, fontMuni, fontTime, font2;
        private TimeSpan timer_reload = TimeSpan.Zero, time = TimeSpan.Zero;

        //Charge le jeu: background, points..
        public void Load(ContentManager Content, GraphicsDeviceManager graphics)
        {
            font = Content.Load<SpriteFont>("Fonts/test");
            font2 = Content.Load<SpriteFont>("Fonts/font2");
            fontMuni = Content.Load<SpriteFont>("Fonts/muni");
            fontTime = Content.Load<SpriteFont>("Fonts/fontemps");
            fond1.Load(Content, "background");
            fond2.Load(Content, "background2");
            croix = Content.Load<Texture2D>("Images/croixVie");
            croix2 = Content.Load<Texture2D>("Images/croixVie2");
            fondVie = Content.Load<Texture2D>("images/viefond");
            fond2.Position.X = graphics.PreferredBackBufferWidth;
        }
        public void Gestion(GameTime gameTime)
        {
            if (timer_reload.Milliseconds >= 999)
            {
                timer_reload = TimeSpan.Zero;
            }

            if(time.Seconds >= 1)
            {
                temps_lvl--;
                time = TimeSpan.Zero;
            }
            timer_reload += gameTime.ElapsedGameTime;
            time += gameTime.ElapsedGameTime;
        }
        //Dessine tout ce qui a été chargé
        public void Draw(SpriteBatch spriteBatch, Joueur player)
        {
            fond1.Draw(spriteBatch);
            fond2.Draw(spriteBatch);
            spriteBatch.Draw(croix, new Vector2(200, 22), Color.White);
            spriteBatch.DrawString(font, "Score: " + Convert.ToString(nbPoints), new Vector2(20, 20), Color.White);
            spriteBatch.DrawString(fontMuni, Convert.ToString(player.ammo), new Vector2(20, 550), Color.White);
            spriteBatch.DrawString(fontTime, Convert.ToString(temps_lvl), new Vector2(333, 10), Color.White);
            spriteBatch.DrawString(font, player.Vie.ToString(), new Vector2(240, 22), Color.White);


            if(multi)
            {
                //Pour l'autre joueur
                spriteBatch.DrawString(font2, "5", new Vector2(490, 20), Color.White);
                spriteBatch.Draw(croix2, new Vector2(520, 22), Color.White);
                spriteBatch.DrawString(font2, "Score: 0", new Vector2(600, 20), Color.White);
            }
        }

        public void Replace(Joueur player, BadGuys ennemi)
        {
            player.Position.X = 50;
            player.Position.Y = 200;
        }

        //gere presque le scrolling
        public void scrolling(Sprite fond1, Sprite fond2, GestionEnnemi gEnnemi, int vitesseJoueur, map Map)
        {
            fond1.Position.X -= vitesseJoueur;
            fond2.Position.X -= vitesseJoueur;
            foreach(BadGuys ennemi in gEnnemi.tabEnnemi1)
            {
                ennemi.Position.X -= vitesseJoueur;
            }
            Map.coefx += vitesseJoueur;

            if (fond1.Position.X <= (-fond1.Size.Width * fond1.Scale))
            {
                fond1.Position.X = fond2.Position.X + (fond2.Size.Width * fond2.Scale);
            }
            else if (fond2.Position.X <= (-fond2.Size.Width * fond2.Scale))
            {
                fond2.Position.X = fond1.Position.X + (fond1.Size.Width * fond1.Scale);
            }
        }
    }
}
